#  -*- coding: utf-8 -*-
from PageObjectRequests import base_url
from util import http_utils
from util.g import g
from util.selenium.webdriver.common.by import By

from base.BaseMethod import BM
from util.DataQuery.FormDataDecorator import FormDataDecorator

from PageObjectRequests.IAMgtTech import IAMgtTech
from PageObjectRequests.IARdmDesc import IARdmDesc
from PageObjectRequests.IARiprIec import IARiprIec
from PageObjectRequests.IAStaDesc import IAStaDesc


class WriteInnovationAbilityForm():
    form_btn_loc = (By.LINK_TEXT, '企业创新能力')
    content_iframe_loc = (By.CSS_SELECTOR, "#innocomFrame")

    # 写代码时方便提示, 基本方法完成后删除
    # driver = driver
    def __init__(self, driver=None):
        self.driver = driver
    @property
    def class_name(self):
        return self.__class__.__name__

    @FormDataDecorator
    def main(self, ripr_iec='', sta_desc='', rdm_desc='', mgt_tech=''):
        # 点击 企业创新能力 表单按钮
        # BM.click(driver=self.driver, ele_loc=self.form_btn_loc)
        ele = BM.get_ele(driver=self.driver, ele_loc=self.form_btn_loc, time=6)
        detail_url = ele.get_attribute("href")
        if not g.all_optimized:
            BM.cut_over_frame(driver=self.driver, selector_loc=self.content_iframe_loc)
        detail_url = detail_url if detail_url.startswith("https://") else \
            base_url + (detail_url if detail_url.startswith("https://") else "/" + detail_url)
        BM.get_cookie(driver=self.driver)
        res = http_utils.send_get(detail_url, driver=self.driver)

        #  实例化 ia_* 四个类对象，然后分别执行 fill_form 方法
        ripr_res = IARiprIec(driver=self.driver, text=ripr_iec, response=res).fill_form()
        sta_info = IAStaDesc(driver=self.driver, text=sta_desc, response=res)
        sta_res = sta_info.fill_form()
        if g.record.sta_status != 1:
            sta_info.ia_sta_desc()
        ia_rdm_desc = IARdmDesc(driver=self.driver, text=rdm_desc, response=res)
        ia_res = ia_rdm_desc.fill_form()
        ia_upload_res = ia_rdm_desc.upload_file()
        mgt_tech_res = IAMgtTech(driver=self.driver, text=mgt_tech, response=res).fill_form()
        return ripr_res and sta_res and ia_res and ia_upload_res and mgt_tech_res

if __name__ == '__main__':
    a = WriteInnovationAbilityForm(driver='fdsji')
    print(a.write_innovation_ability_form.__code__.co_varnames)
